<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
/**
* //类型属性控制器	
*/
class TypeAttController extends CommonController
{
	private $model;
	public function __init()
	{
		parent::__init();
		$this->model=new \Common\Model\TypeAtt;
	}
	public function index()
	{
		$data=$this->model->get();
		foreach ($data as $k=> $v) {
			$data[$k]['tname']=Db::table('type')->where("tid={$v['type_tid']}")->pluck('tname');
		};
		View::with('data',$data);
		View::make();
	}
	public function add()
	{
		$type_tid=Q('get.type_tid');
		View::with('type_tid',$type_tid);
		if (IS_POST) {
			if ($this->model->store()) {
				View::success('添加成功',U('index'));
			}
		}
		View::make();
	}
	public function del()
	{
		$taid=Q('get.taid');
		$this->model->where("taid={$taid}")->delete();	
		View::success('删除成功',U('index'));
	}
	public function edit()
	{
		$taid=Q('get.taid');
		if (IS_POST) {
			if (!$this->model->edit($taid)) View::error($this->model->getError());
			View::success('修改成功',U('index'));
		}
		$olddata=$this->model->where("taid={$taid}")->find();
		View::with('olddata',$olddata);
		View::make();
	}
}

 ?>